package com.coded2.mobileposto.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.inject.Inject;

import com.coded2.infra.comum.ComumService;
import com.coded2.mobileposto.dao.CombustivelDAO;
import com.coded2.mobileposto.dao.DistribuidorDAO;
import com.coded2.mobileposto.dao.PostoDAO;
import com.coded2.mobileposto.dao.ServicoDAO;
import com.coded2.mobileposto.model.Combustivel;
import com.coded2.mobileposto.model.Distribuidor;
import com.coded2.mobileposto.model.Posto;
import com.coded2.mobileposto.model.PostoCombustivel;
import com.coded2.mobileposto.model.Servico;

public class PostoService extends ComumService<Posto> {

	private static final long serialVersionUID = 1L;

	@Inject
	PostoDAO dao;

	@Inject
	DistribuidorDAO disDAO;
	
	@Inject
	ServicoDAO serDAO;
	
	@Inject
	CombustivelDAO combDAO;
	
	@Override
	public List<Posto> search(Posto obj) throws Exception {			
		return dao.search(obj);	
	}
	
	@Override
	public Posto searchByID(Posto model) throws Exception {
		return dao.searchById(model);
	}

	public List<Distribuidor> recuperaDistribuidores() {
		List<Distribuidor> lista = new ArrayList<Distribuidor>();
		try {
		lista = disDAO.search(new Distribuidor());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lista;
	}

	public List<Servico> recuperarServicos() {
		List<Servico> lista = new ArrayList<Servico>();
		try {
		lista = serDAO.search(new Servico());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lista;
	}

	public Collection<Combustivel> recuperarCombustiveis() {
		List<Combustivel> lista = new ArrayList<Combustivel>();
		try {
		lista = combDAO.search(new Combustivel());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lista;
	}

	public void deleteCombustiveis(Posto posto) {
		dao.deleteCombustiveis(posto);
	}

	public Collection<Combustivel> searchByCombustiveis() {
		return dao.searchByCombustiveis();
	}

	public void saveServico(Servico _ser, int idPosto) {
		dao.insertServico(_ser, idPosto);
	}

	public List<Servico> searchByServicos(Posto posto) {
		return dao.searchByServicos(posto); 
	}

	public void deleteServicos(Posto posto) {
		dao.deleteServicos(posto);
	}
	
}
